home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01a.txt / 000072_icon-group-sender _Tue Jun 27 16:59:29 2000.msg < prev    next >
Internet Message Format  |  2002-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA21185
  4.     for icon-group-addresses; Tue, 27 Jun 2000 16:59:18 -0700 (MST)
  5. Message-Id: <200006272359.QAA21185@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 27 Jun 2000 16:38:22 -0400
  7. From: "Steve Graham" <Steve_Graham@labcorp.com>
  8. To: <icon-group@optima.CS.Arizona.EDU>
  9. Subject: Re: Permutations/Combinations
  10. Content-Disposition: inline
  11. X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id NAA15678
  12. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  13. Status: RO
  14. Content-Length: 1544
  15.  
  16. Gregg,
  17.  
  18.    That's exactly what I was looking for.  Now, let me have some time to ponder why it works...
  19.  
  20. ---------------------------------------------------------------------------------------
  21. Steve Graham
  22. Senior Programmer/Analyst
  23. LabCorp
  24.  
  25. Phone: (972) 437-5255, ext 5224
  26. Fax:     (972) 454-1040
  27. Mail:    grahams@labcorp.com
  28. ---------------------------------------------------------------------------------------
  29.  
  30.  
  31. >>> Gregg Townsend <gmt@baskerville.CS.Arizona.EDU> 06/27/00 03:08PM >>>
  32.     From: "Steve Graham" <Steve_Graham@labcorp.com>
  33.     
  34.     Although I do not know how to utilize Icon's built-in features to generate
  35.     all possible combinations/permutations (which one is it?) where the letters
  36.     appear once and only once, I do believe that, given the generated list, I
  37.     will recognize the valid words.  And I'm sure that Icon can EASILY produce
  38.     the list, whether the algorthim utilizes reversible assignment or not.
  39.     Can someone show me how?
  40.     
  41. The Icon program library contains a nice little permutation generator
  42. (in the procs/strings.icn file):
  43.  
  44.     procedure permute(s)
  45.        local i
  46.        if *s = 0 then return ""
  47.           suspend s[i := 1 to *s] || permute(s[1:i] || s[i+1:0])
  48.     end
  49.  
  50. So to generate all 720 permutations you'd just do this:
  51.  
  52.     procedure main()
  53.        every write(permute("abelmr"))
  54.     end
  55.  
  56.    ---------------------------------------------------------------------------
  57.    Gregg Townsend         Staff Scientist      The University of Arizona
  58.    gmt@cs.arizona.edu     Computer Science     Tucson, Arizona, USA
  59.  
  60.